home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / install.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  3.8 KB  |  140 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (c) Copyright 2003-2007 Hewlett-Packard Development Company, L.P.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  19. #
  20. # Author: Don Welch
  21. #
  22.  
  23. __version__ = '1.0'
  24. __title__ = 'HPLIP Installer'
  25. __doc__ = "Installer for HPLIP tarball."
  26.  
  27.  
  28. # Std Lib
  29. import getopt, os, os.path, sys
  30.  
  31. # Local
  32. from base.g import *
  33. from base import utils
  34. from installer import core
  35.  
  36.  
  37. USAGE = [(__doc__, "", "name", True),
  38.          ("Usage: sh ./hplip-install [MODE] [OPTIONS]", "", "summary", True),
  39.          utils.USAGE_SPACE,
  40.          ("[MODE]", "", "header", False),
  41.          #("Enter browser (web) UI mode:", "-w or --web or --browser", "option", False),
  42.          ("Run in interactive mode:", "-i or --interactive (Default)", "option", False),
  43.          utils.USAGE_SPACE,
  44.          utils.USAGE_OPTIONS,
  45.          ("Automatic mode (chooses the most common options):", "-a or --auto", "option", False),
  46.          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
  47.          utils.USAGE_HELP,
  48.          utils.USAGE_SPACE,
  49.          utils.USAGE_NOTES,
  50.         ]
  51.  
  52. def usage(typ='text'):
  53.     if typ == 'text':
  54.         utils.log_title(__title__, __version__)
  55.  
  56.     utils.format_text(USAGE, typ, __title__, 'hplip-install', __version__)
  57.     sys.exit(0)        
  58.  
  59.  
  60. log.set_module("hplip-install")
  61.  
  62. log.debug("euid = %d" % os.geteuid())
  63. mode = INTERACTIVE_MODE
  64. auto = False
  65.  
  66. try:
  67.     opts, args = getopt.getopt(sys.argv[1:], 'hl:guiaw', 
  68.         ['help', 'help-rest', 'help-man', 'help-desc',
  69.         'logging=', 'interactive', 'auto', 'web', 'browser']) 
  70.  
  71. except getopt.GetoptError:
  72.     usage()
  73.     sys.exit(1)
  74.  
  75. if os.getenv("HPLIP_DEBUG"):
  76.     log.set_level('debug')
  77.  
  78. for o, a in opts:
  79.     if o in ('-h', '--help'):
  80.         usage()
  81.  
  82.     elif o == '--help-rest':
  83.         usage('rest')
  84.  
  85.     elif o == '--help-man':
  86.         usage('man')
  87.  
  88.     elif o == '--help-desc':
  89.         print __doc__,
  90.         sys.exit(0)
  91.  
  92.     elif o in ('-l', '--logging'):
  93.         log_level = a.lower().strip()
  94.         if not log.set_level(log_level):
  95.             usage()
  96.  
  97.     elif o == '-g':
  98.         log.set_level('debug')
  99.  
  100.     elif o in ('-i', '--interactive'):
  101.         mode = INTERACTIVE_MODE
  102.  
  103.     elif o in ('-a', '--auto'):
  104.         auto = True
  105.  
  106.     elif o in ('-w', '--browser', '--web'):
  107.         mode = BROWSER_MODE
  108.  
  109.  
  110. log_file = os.path.normpath('./install.log')
  111. if os.path.exists(log_file):
  112.     os.remove(log_file)
  113.  
  114. log.set_logfile(log_file)
  115. log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
  116.  
  117. log.debug("Log file=%s" % log_file)
  118.  
  119. version_description, version_public, version_internal = core.getHPLIPVersion()
  120. log.debug("HPLIP Description=%s Public version=%s Internal version = %s"  % 
  121.     (version_description, version_public, version_internal))
  122.  
  123. prop.version = version_public
  124. utils.log_title(__title__, __version__)
  125.  
  126. if mode == BROWSER_MODE:
  127.     from installer import web_install
  128.     log.debug("Starting web browser installer...")
  129.     web_install.start()
  130.  
  131. elif mode == INTERACTIVE_MODE:
  132.     from installer import text_install
  133.     log.debug("Starting text installer...")
  134.     text_install.start(auto)
  135.  
  136. else:
  137.     log.error("Invalid mode. Please use '-i' or '-w' to select the mode.")
  138.     sys.exit(1)
  139.  
  140.